package org.flashbrighton.as3bots.views.ui.scores 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.text.*;
	import org.flashbrighton.as3bots.bots.BaseBot;
	import org.flashbrighton.as3bots.models.BotModel;
	
	
	public class BotScore extends Sprite
	{
		private var _bot:BaseBot;
		private var _botModel:BotModel;
		private var _bar:HealthBar;
		
		
		public function BotScore(botModel:BotModel) 
		{
			_botModel = botModel;
			_bot = _botModel.bot;
			init();
		}
		
		
		public function update():void 
		{
			_bar.update();
		}
		
		
		private function init():void
		{
			var thumbWidth:int = 30;
			var thumbHeight:int = 30;
			
			var bmd:BitmapData = new BitmapData(thumbWidth,thumbHeight, true, 0xFFFFFF);
			var mtx:Matrix = new Matrix();
			mtx.translate(thumbWidth / 2, thumbHeight / 2);
			bmd.draw(_bot.skin, mtx);
			var thumbnail:Bitmap = new Bitmap(bmd, "auto", true);
			addChild(thumbnail);
			
			_bar = new HealthBar(_botModel);
			_bar.x = thumbWidth;
			_bar.y = 7;
			addChild(_bar);
			
			var label:TextField = createLabel(_bot.botName.toUpperCase());
			label.x = thumbWidth;
			label.y = 9;
			addChild(label);
		}
		
		
		private function createLabel(text:String):TextField 
		{
			var tf:TextField = new TextField();
			tf.embedFonts = true;
			tf.defaultTextFormat = new TextFormat("Gradius", 8, 0xFFFFFF);
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.text = text;
			return tf;
		}
		
	}

}